package org.example.domain.canal.service;

import org.example.domain.canal.repository.ICanalRepository;
import org.example.types.common.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;

@Service
public class CanalService implements ICanalService {

    @Resource
    private ICanalRepository canalRepository;

    /**
     * 删除基于mq传过来的binlog消息
     * Strategy_award表
     * @param map
     */
    @Override
    public void deleteStrategyAwardRedisByCanalMqMap(HashMap<String, Object> map) {
        if (!map.isEmpty() && map.get("database").toString().equals("big_market")) {
            if(map.get("table").toString().equals("strategy_award")){
                ArrayList<LinkedHashMap<String,String>> datas = (ArrayList<LinkedHashMap<String, String>>) map.get("data");
                for(LinkedHashMap<String,String> data:datas){
                    String cacheKey = Constants.RedisKey.STRATEGY_AWARD_KEY + data.get("strategy_id") + Constants.UNDERLINE + data.get("award_id");
                    canalRepository.deleteRedis(cacheKey);
                }
            }
        }
    }
}
